# coding: UTF-8
import urllib2
from bs4 import BeautifulSoup
import MySQLdb

url = 'http://adamee.duapp.com/'
require = urllib2.Request(url)
html = urllib2.urlopen( require )
soup = BeautifulSoup(html.read())

try:
    conn=MySQLdb.connect(host='localhost',user='root',passwd='oseasy',port=3306,charset = 'utf8')
    cur=conn.cursor()     
    cur.execute('create database if not exists Test')
    conn.select_db('Test')
    cur.execute('create table if not exists abc(title char(64) primary key,href char(64))')
    values=[]
    for link in soup.find_all('a',attrs={'class':'btn'}):
        values.append((link.get('href'),link.get_text()))
    cur.executemany('insert into abc values(%s,%s)',values)
    conn.commit()
    cur.close()
    conn.close()
except MySQLdb.Error,e:
    print "Mysql Error %d: %s" % (e.args[0], e.args[1])
